package com.tmsps.ne4Weixin.api;

import com.alibaba.fastjson.JSONObject;
import com.tmsps.ne4Weixin.api.entity.menu.Menu;
import com.tmsps.ne4Weixin.beans.BaseBean;
import com.tmsps.ne4Weixin.config.WxConfig;
import com.tmsps.ne4Weixin.utils.HttpClient;

/**
 * 
 * @author zhangwei 396033084@qq.com MenuAPI 菜单API
 */
public class MenuAPI extends BaseAPI {
	private static final String CREATEDMENU = BaseURL.concat("/cgi-bin/menu/create?access_token=%s");
	private static final String GETMENU = BaseURL.concat("/cgi-bin/menu/get?access_token=%s");
	private static final String DELETEMENU = BaseURL.concat("/cgi-bin/menu/delete?access_token=%s");

	public MenuAPI(WxConfig config) {
		super(config);
	}

	public BaseBean createMenu(Menu menu) {
		String result = HttpClient.postJson(String.format(CREATEDMENU, config.getAccessToken()), menu.toJson());
		return JSONObject.parseObject(result, BaseBean.class);
	}

	public BaseBean createMenu(String menuJSON) {
		String result = HttpClient.postJson(String.format(CREATEDMENU, config.getAccessToken()), menuJSON);
		return JSONObject.parseObject(result, BaseBean.class);
	}

	public String getMenu() {
		String result = HttpClient.httpGet(String.format(GETMENU, config.getAccessToken()), null);
		return result;
	}

	public String deleteMenu() {
		String result = HttpClient.httpGet(String.format(DELETEMENU, config.getAccessToken()), null);
		return result;
	}

}
